import Vue from 'vue'
import Vuex from 'vuex'
import api from '@/api/index.js'

Vue.use(Vuex)
// console.log(this.$store.stata, 111111111111);

export default new Vuex.Store({
  state: {
    skeletonRow: 28,
    code: "",
    access_token: "",
    openid: "obD_t1D_-_MgWCD3T3Jtk6GPdCUw", // qt obD_t1CJQMV3LhLx0psum-iUdudI  dx obD_t1D_-_MgWCD3T3Jtk6GPdCUw zw obD_t1IWb-PCqNTW9GoIUOCGGoog
    // openid: "",
    appid: "",
    secret: "",
    masterColor: "#FF0000",
    isLogin: false,
    tabbar: [],
    swipeList: [],
    caseTabsList: [],
    caseList: [],
    caseListFinished: false,
    caseItem: "",
    activityItem: "",
    offeredItem: {},
    userInfo: "",
    saveItem: {},
    group_id: null,
    p_openid: '',
    envelopeList: [],
    theme_color: '',
    btn_color: '',
    cashout: [],
    cashin: [],
    val: [],
    prizeText: '',
    objParams: {},
    mergeList: [],
    merchant: {},
    presentPrice: '',
    productList: [],
    goods: [],
    orderItem: JSON.parse(window.localStorage.getItem('OrderItem')) || {},
    // saveItem: JSON.parse(window.localStorage.getItem ('OrderItem')) || {} setprizeItem
  },
  mutations: {
    // updateGoodsState(state, goods) {
    //   const findResult = state.productList.find(x => x.id == goods.id)
    //   // console.log(findResult, 1);
    //   if (findResult) {
    //     findResult.goods_status = goods.goods_status
    //     // console.log(findResult, 2);
    //     // this.commit('saveToStorage')
    //   }
    // },
    getProductList(state, rawData) {
      state.productList = rawData;
      console.log(state.productList, "-----------productList-------------")
    },
    setPresentPrice(state, rawData) {
      state.presentPrice = rawData;
      console.log(state.presentPrice, "-----------presentPrice-------------")
    },
    setMerchant(state, rawData) {
      state.merchant = rawData;
      console.log(state.merchant, "-----------merchant-------------")
    },
    setMergeList(state, rawData) {
      state.mergeList = rawData;
      console.log(state.mergeList, "mergeList")
    },
    setObjParams(state, rawData) {
      state.objParams = rawData;
      console.log(state.objParams, "objParams")
    },
    setCashout(state, rawData) {
      state.cashout = rawData;
      console.log(state.cashout, "cashout")
    },
    setCashin(state, rawData) {
      state.cashin = rawData;
      console.log(state.prizeText, "cashin")
    },
    setprizeItem(state, rawData) {
      state.prizeText = rawData;
      console.log(state.prizeText, "prizeText")
    },
    setVal(state, rawData) {
      state.val = rawData;
      console.log(state.val, "val")
    },
    setThemeColor(state, rawData) {
      state.theme_color = rawData;
      this.commit('setLocalOrderItem')
      console.log(state.theme_color, "theme_color")
    },
    setBtnColor(state, rawData) {
      state.btn_color = rawData;
      this.commit('setLocalOrderItem')
      console.log(state.btn_color, "btn_color")
    },
    setEnvelopeItem(state, rawData) {
      state.envelopeList = rawData;
      console.log(state.envelopeList, "envelopeList")
    },
    setpopenid(state, rawData) {
      state.p_openid = rawData;
      console.log(state.p_openid, "p_openid")
    },
    setgroupId(state, rawData) {
      state.group_id = rawData;
      console.log(state.group_id, "group_id")
    },
    setSaveItem(state, rawData) {
      state.saveItem = rawData;
      this.commit('setLocalOrderItem')
      console.log(state.saveItem, "saveItem")
    },
    setOfferedItem(state, rawData) {
      state.offeredItem = rawData;
      this.commit('setLocalOrderItem')
      console.log(state.offeredItem, "offeredItem")
    },
    setOrderItem(state, rawData) {
      state.orderItem = rawData;
      this.commit('setLocalOrderItem')
      console.log(state.orderItem, "orderItem")
    },
    setAppid(state, rawData) {
      state.appid = rawData;
      console.log(state.appid, "appid")
    },
    setSecret(state, rawData) {
      state.secret = rawData;
      console.log(state.secret, "secret")
    },
    setActivityData(state, rawData) {
      state.activityData = rawData;
      console.log(state.activityData, "activityData")
    },
    setUserInfo(state, rawData) {
      state.userInfo = rawData;
      console.log(state.userInfo, "userInfo")
    },
    setAccessToken(state, rawData) {
      state.access_token = rawData;
      console.log(state.access_token, "access_token")
    },
    setOpenid(state, rawData) {
      state.openid = rawData;
      console.log(state.openid, "openid")
    },
    setCode(state, rawData) {
      state.code = rawData;
      console.log(state.code, "code")
    },
    setCaseTabsList(state, rawData) {
      state.caseTabsList = rawData;
    },
    setCaseList(state, rawData) {
      state.caseList = rawData;
    },
    setCaseListFinished(state, b) {
      state.caseListFinished = b;
    },
    setCaseItem(state, rawData) {
      state.caseItem = rawData;
    },
    setActivityItem(state, rawData) {
      state.activityItem = rawData;
    },
    setSwipeList(state, rawData) {
      state.swipeList = rawData;
    },
    setTabbar(state, rawData) {
      state.tabbar = rawData;
    },
    setColor(state, rawData) {
      state.mainColor = rawData;
      console.log(state.mainColor)
    },
    setMasterColor(state, rawData) {
      state.masterColor = rawData;
      console.log(state.masterColor)
    },
    // 存储vuex数据
    setLocalOrderItem(stata) {
      window.localStorage.setItem('OrderItem', JSON.stringify(stata))
    },
    // // 持久化存储商品数据
    // saveToStorage(state) {
    //   window.localStorage.setItem('cart_goods', JSON.stringify(state.goods))
    // }
  },
  actions: {
    async getCaseList(context, params = {
      type_id: 0,
      pageNo: 1,
      pageSize: 10
    }) {
      await api.getCaseList(params).then(res => {
        console.log("res", res)
        context.commit('setCaseList', res.data);
        return res.data;
      })
    },
  },
  getters: {
    getOpenid(state) {
      return state.openid;
    },
    getMasterColor(state) {
      return state.masterColor;
    },
    getMainColor(state) {
      return state.masterColor;
    },
    getTabbar(state) {
      return state.tabbar;
    },
    getSwipeList(state) {
      return state.swipeList;
    },
    getCaseTabsList(state) {
      return state.caseTabsList;
    },
    getCaseList(state) {
      return state.caseList;
    },
    getCaseListFinished(state) {
      return state.caseListFinished;
    },
    getCaseItem(state) {
      return state.caseItem;
    },
    getActivityItem(state) {
      return state.activityItem;
    },
    getSaveItem(state) {
      return state.saveItem;
    },
    getOrderItem(state) {
      return state.orderItem;
    }
  },
  modules: {}
})